package com.atguigu.lease.common.exception;


import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * projectName: com.atguigu.lease.common.exception
 *
 * @author: Aiolin
 * description:
 * time: 2025/5/6 下午4:36
 */
//全局统一异常处理
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result globalExceptionHandler(Exception ex){
        ex.printStackTrace();
        return Result.fail();
    }
    @ExceptionHandler(LeaseException.class)
    @ResponseBody
    public Result leaseExceptionHandler(LeaseException ex){
        ex.printStackTrace();
        return Result.fail(ex.getCode(),ex.getMessage());
    }
}
